package com.my.mvpframe.utils;


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

/**
 * toast util to show the util.
 */
public class ToastUtil {

	public static void ShowLong(Context context, CharSequence text) {
		if (context != null) {
			Toast t = Toast.makeText(context, text, Toast.LENGTH_LONG);
			t.setGravity(Gravity.CENTER, 0, 0);
			t.show();
		}
	}

	public static void ShowLong(Context context, int reid) {
		if (context != null) {
			Toast t = Toast.makeText(context,
					context.getResources().getString(reid), Toast.LENGTH_LONG);
			t.setGravity(Gravity.CENTER, 0, 0);
			t.show();
		}
	}

	public static void ShowShort(Context context, CharSequence text) {
		if (context != null) {
			Toast t = Toast.makeText(context, text, Toast.LENGTH_SHORT);
			t.setGravity(Gravity.CENTER, 0, 0);
			t.show();
		}
	}

	public static void ShowShort(Context context, int reid) {
		if (context != null) {
			Toast t = Toast.makeText(context,
					context.getResources().getString(reid), Toast.LENGTH_SHORT);
			t.setGravity(Gravity.CENTER, 0, 0);
			t.show();
		}
	}

	/**
	 * icon被强制为44*44，放在文本的左边，并且toast没有背景
	 * 
	 * @param context
	 * @param resId
	 * @param text
	 * @param duration
	 */
	public static void showIconToast(Context context, int resId,
			CharSequence text, int duration) {
		Toast toast = new Toast(context);
		TextView contentView = new TextView(context);
		Drawable drawable = context.getResources().getDrawable(resId);
		drawable.setBounds(0, 0, 44, 44);

		contentView.setCompoundDrawables(drawable, null, null, null);
		contentView.setGravity(Gravity.CENTER_VERTICAL);
		contentView.setTextSize(20);
		contentView.setText(text);
		contentView.setCompoundDrawablePadding(5);

		toast.setView(contentView);
		toast.setDuration(duration);
		toast.show();
	}
}
